<form action="<?php echo $controller;?>showlist/1" method="get" class="filter-form-wrap" enctype="multipart/form-data">
    <div class="filter-wrap flex-row flex-justify-between flex-align-start flex-nowrap">
        <div class="flex-column flex-justify-center flex-align-start flex-nowrap" style="width: 50%;">
            <div class="flex-row flex-justify-start flex-nowrap flex-align-center marginTB-5">
                <span style="width: 60px;">加入时间</span>
                <input type="text" name="start" id="startpicker" class="marginLR-5" value="<?php if (isset($start)):?><?php echo $start;?><?php endif;?>">
                <span style="width: 20px;">至</span>
                <input type="text" name="end" id="endpicker" class="marginLR-5" value="<?php if (isset($end)):?><?php echo $end;?><?php endif;?>">
            </div>
            <div class="flex-row flex-justify-start flex-nowrap flex-align-center marginTB-5">
                <span style="width: 60px;">销售员ID</span>
                <input type="text" name="fidcode" class="marginLR-5" style="width: 330px;" value="<?php if (isset($fidcode)):?><?php echo $fidcode;?><?php endif;?>">
            </div>
            <div class="flex-row flex-justify-start flex-nowrap flex-align-center marginTB-5">
                <span style="width: 60px;">销售员名称</span>
                <input type="text" name="fname" class="marginLR-5" style="width: 330px;" value="<?php if (isset($fname)):?><?php echo $fname;?><?php endif;?>">
            </div>
            <div class="flex-row flex-justify-start flex-nowrap flex-align-center marginTB-5">
                <span style="width: 60px;">微信昵称</span>
                <input type="text" name="fusername" class="marginLR-5" style="width: 330px;" value="<?php if (isset($fusername)):?><?php echo $fusername;?><?php endif;?>">
            </div>
            <div class="flex-row flex-justify-start flex-nowrap flex-align-center marginTB-5">
                <span style="width: 60px;">手机</span>
                <input type="text" name="fphone" class="marginLR-5" style="width: 330px;" value="<?php if (isset($fphone)):?><?php echo $fphone;?><?php endif;?>">
            </div>
        </div>
        <div class="flex-column flex-justify-center flex-align-start flex-nowrap" style="width: 50%;">
            <div class="flex-row flex-justify-start flex-nowrap flex-align-center marginTB-5">
                <span style="width: 60px;">上线</span>
                <input type="text" name="finvi" class="marginLR-5" style="width: 330px;" value="<?php if (isset($finvi)):?><?php echo $finvi;?><?php endif;?>">
            </div>
            <div class="flex-row flex-justify-start flex-nowrap flex-align-center marginTB-5">
                <span style="width: 60px;">渠道</span>
                <select name="ftype" class="marginLR-5">
                    <option value="">全部</option>
                    <?php foreach ($slstypes as $st=>$sn):?>
                        <option value="<?php echo $st;?>" <?php if (isset($ftype)&&$ftype == $st):?><?php echo 'selected';?><?php endif;?>>
                            <?php echo $sn;?>
                        </option>
                    <?php endforeach;?>
                </select>
            </div>
            <div class="flex-row flex-align-start flex-justify-start marginTB-5">
                <div class="filter-btn btn">筛选</div>
                <div class="reset-btn btn" style="margin:0 10px;">重置</div>
            </div>
            <div class="flex-row flex-align-start flex-justify-start marginTB-5">
                <div class="coupon-batch-btn btn" style="background-color: #1dd697;">批量发券</div>
                <div class="sync-coupon-btn btn" style="margin:0 10px;background-color: #e01a1a;">同步优惠券</div>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
    var config = {showAnim:'drop',dateFormat:'yy-mm-dd',changeMonth:true,changeYear: true,
        monthNamesShort:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]};
    $('#startpicker').datepicker(config);
    $('#endpicker').datepicker(config);
    $('.coupon-batch-btn').on('click',function () {
        var content = '<div style="padding:10px 15px;">' +
            '<label for="coupon-type">发券给</label>' +
            '<select name="coupon-type" id="coupon-type">' +
            '<option value="ALL">所有人</option>' +
            <?php foreach ($slstypes as $st=>$sn):?>
            '<option value="<?php echo $st;?>"><?php echo $sn;?></option>' +
            <?php endforeach;?>
            '</select>' +
            '</div>' +
            '<fieldset>' +
            <?php foreach ($coupons as $k=>$c):?>
            '<label for="coupon<?php echo $c['couponid'];?>"><?php echo $c['title'];?></label>' +
            '<input type="checkbox" name="coupon<?php echo $c['couponid'];?>" id="coupon<?php echo $c['couponid'];?>" value="<?php echo $c['couponid'];?>">' +
            <?php endforeach;?>
            '</fieldset>';
        layer.open({
            title:'',
            type:1,
            content:content,
            offset:'100px',
            btn:['选择','取消'],
            btnAlign:'c',
            yes:function () {
                var coupontype = $('select[name="coupon-type"]').val();
                var coupons='';
                $('input[type="checkbox"]:checked').each(function () {
                    coupons+=$(this).val()+'|';
                });
                console.log(coupontype,coupons);
                if (coupons){
                    layer.confirm('确定发券么？',{title:'',offset:'100px'},function (index) {
                        layer.close(index);
                        layer.open({type:3,offset:'100px'});
                        $.ajax({
                            url:'http://admin.nldou.com/admin/salesman/kdtsalesman/addBatchCoupons',
                            method:'GET',
                            data:{coupontype:coupontype,coupons:coupons},
                            dataType:"json",
                            xhrFields: {withCredentials: true},
                            success:function (res) {
                                if(res.code=1) {
                                    layer.closeAll();
                                    layer.msg('发券成功',{offset:'100px'});
                                }
                            }
                        });
                    });
                }else{layer.msg('请选择优惠券',{offset:'100px'});}
            }
        });
        $('input[type="checkbox"]').checkboxradio({icon:false});
    });
    $('.sync-coupon-btn').on('click',function () {
        window.location.href = 'http://admin.nldou.com/admin/salesman/kdtsalesman/synCoupon';
    });
    $(document).on('click','.other-btn.action-btn',function () {
        var loader=layer.open({type:3,offset:'100px'});
        var smid = $(this).attr('data-pkey');
        $.ajax({
            url:'http://admin.nldou.com/admin/salesman/kdtsalesman/editCoupons',
            method:'GET',
            data:{id:smid},
            dataType:"json",
            xhrFields: {withCredentials: true},
            success:function (res) {
                layer.close(loader);
                var coupons = res.data;
                var content = '<fieldset>';
                for(var i in coupons){
                    content+='<label for="coupon'+coupons[i].couponid+'">'+coupons[i].title+'</label>';
                    content+='<input type="checkbox" name="coupon'+coupons[i].couponid+'" id="coupon'+coupons[i].couponid+'" value="'+coupons[i].couponid+'"';
                    if(coupons[i].checked==1) content+=' checked';
                    content+='>'
                }
                content+='</fieldset>';
                layer.open({
                    title:'',
                    type:1,
                    content:content,
                    offset:'100px',
                    btn:['修改','取消'],
                    btnAlign:'c',
                    yes:function () {
                        var coupons='';
                        $('input[type="checkbox"]:checked').each(function () {
                            coupons+=$(this).val()+'|';
                        });
                        layer.confirm('确定保存修改么？',{title:'',offset:'100px'},function (index) {
                            layer.close(index);
                            layer.open({type:3,offset:'100px'});
                            $.ajax({
                                url:'http://admin.nldou.com/admin/salesman/kdtsalesman/editCoupons',
                                method:'GET',
                                data:{id:smid,coupons:coupons},
                                dataType:"json",
                                xhrFields: {withCredentials: true},
                                success:function (res) {
                                    if(res.code=1) {
                                        layer.closeAll();
                                        layer.msg('保存成功',{offset:'100px'});
                                    }
                                }
                            });
                        });
                    }
                });
                $('input[type="checkbox"]').checkboxradio({icon:false});
            }
        })
    });
</script>